package org.lqq.entity;

public class Page {

    private PageSupport pageSupport;

    public Page(PageSupport pageSupport){
        this.pageSupport=pageSupport;
    }

    @Override
    public String toString() {
        StringBuilder sb=new StringBuilder();
        int index=pageSupport!=null&&pageSupport.getPageIndex()!=null?pageSupport.getPageIndex():0;
        int size=pageSupport!=null&&pageSupport.getPageSize()!=null?pageSupport.getPageSize():10;

        int current=0;
        if(index%size>0){
            current=index/size+1+1;
        }else {
            current=index/size+1;
        }
        int count=pageSupport.getPageCount();
        int allPage=0;
        if(count%size>0){
            allPage=count/size+1;
        }else {
            allPage=count/size;
        }
        for(int i=1;i<=allPage;i++) {
            if(current!=i) {
                sb.append("<a href=\"javascript:page(").append((i-1)*size).append(")\">").append(i).append("</a>");
            }else {
                sb.append(i);
            }
            sb.append("&nbsp;&nbsp;");
        }
        return sb.toString();
    }
}
